/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package businessDelegates;

import businessObjects.Cliente;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionFacades.ClienteFacadeRemote;

/**
 *
 * @author williamprado
 */
@EJB(name="clientefr", beanInterface = ClienteFacadeRemote.class)
public class ClienteBusinessDelegate {

    public ClienteBusinessDelegate(){

    }

    public void registrarCliente(Cliente cliente){
        try {
            Context ctx = new InitialContext();
            ClienteFacadeRemote clienteFacadeBean = (ClienteFacadeRemote) ctx.lookup("java:comp/env/clientefr");
            clienteFacadeBean.registrarCliente(cliente);
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Cliente login(String login, String pass){
        try {
            Context ctx = new InitialContext();
            ClienteFacadeRemote clienteFacadeBean = (ClienteFacadeRemote) ctx.lookup("java:comp/env/clientefr");
            Cliente cl = clienteFacadeBean.login(login, pass);
            return cl;
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public Cliente consultarCliente(String login){
        try {
            Cliente c = new Cliente();
            Context ctx = new InitialContext();
            ClienteFacadeRemote clienteFacadeBean = (ClienteFacadeRemote) ctx.lookup("java:comp/env/clientefr");
            c = clienteFacadeBean.consultarCliente(login);
            return c;
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public void actualizarCliente(Cliente cliente){
        try {
            Context ctx = new InitialContext();
            ClienteFacadeRemote clienteFacadeBean = (ClienteFacadeRemote) ctx.lookup("java:comp/env/clientefr");
            clienteFacadeBean.actualizarCliente(cliente);
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void eliminarCliente(String login){
        try {
            Context ctx = new InitialContext();
            ClienteFacadeRemote clienteFacadeBean = (ClienteFacadeRemote) ctx.lookup("java:comp/env/clientefr");
            clienteFacadeBean.eliminarCliente(login);
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
